#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ret = nums[0];
        int sum = 0;
        for (auto n : nums)
        {
            sum += n;
            ret = max(ret, sum);
            if (sum < 0) sum = 0;
        }
        return ret;
    }
};
